package com.googlecode.syper.javasyp.config;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;

/**
 * @author kevin
 * @since Mar 1, 2010
 */
public class JavaSypPreferenceInitializer extends
		AbstractPreferenceInitializer {

	// ALWAYS CALL setDefault() methods here, NOT setValue()
	@Override
	public void initializeDefaultPreferences() {
		/*
		 * Initialize Z3 location
		 */
		String dflt = "";
		for (String l : getStandardZ3Locations()) {
			// try a couple of likely locations for Z3
			if (new File(l).exists()) {
				dflt = l;
				break;
			}
		}

		JavaSypPreferences.getPreferences().setDefault(
				JavaSypPreferences.getExecutablePreferenceKey(JavaSypPreferences.SMT_SOLVER_Z3),
				dflt);

		/*
		 * Initialize shared solver timeout
		 */
		JavaSypPreferences.getPreferences().setDefault(
				JavaSypPreferences.getTimeoutPreferenceKey(), 5);

		/*
		 * Initialize show counterexample flag
		 */
		JavaSypPreferences.getPreferences().setDefault(
				JavaSypPreferences.getShowCounterexamplePreferenceKey(), true);

		/*
		 * Initialize prove assume statements flag
		 */
		JavaSypPreferences.getPreferences().setDefault(
				JavaSypPreferences.getProveAssumptionsPreferenceKey(), true);
	}

	private List<String> getStandardZ3Locations() {
		List<String> result = new ArrayList<String>(8);
		result.add("C:\\Program Files\\Microsoft Research\\Z3-2.7\\x64\\z3.exe");
		result.add("C:\\Program Files (x86)\\Microsoft Research\\Z3-2.7\\x64\\z3.exe");
		result.add("C:\\Program Files\\Microsoft Research\\Z3-2.7\\bin\\z3.exe");
		result.add("C:\\Program Files (x86)\\Microsoft Research\\Z3-2.7\\bin\\z3.exe");
		result.add("C:\\Program Files\\Microsoft Research\\Z3-2.4\\x64\\z3.exe");
		result.add("C:\\Program Files (x86)\\Microsoft Research\\Z3-2.4\\x64\\z3.exe");
		result.add("C:\\Program Files\\Microsoft Research\\Z3-2.4\\bin\\z3.exe");
		result.add("C:\\Program Files (x86)\\Microsoft Research\\Z3-2.4\\bin\\z3.exe");
		return result;
	}

}